(function() {
    var E;
    var F;
    var C;
    var B = YAHOO.lang;
    var A = YAHOO.util.Event;
    var D = YAHOO.util.CustomEvent;
    IMO.Manager.ActivityManager = function() {
        this.observed_activity = false;
        this.report_timer = null;
        this.init()
    };
    IMO.Manager.ActivityManager.prototype = {
        NAME: "IMO.Manager.ActivityManager",
        REPORT_INTERVAL: 60000,
        evActivity: new D("user_activity"),
        reportActivity: function() {
            if (this.observed_activity) {
                console.log("reporting activity");
                C.execute_rpc("observed_user_activity", {
                    ssid: F.ssid
                })
            }
            this.observed_activity = false;
            firePopupEvent("start_activity_collection", null, null)
        },
        recordActivity: function() {
            this.observed_activity = true;
            firePopupEvent("stop_activity_collection", null, null);
            this.evActivity.fire()
        },
        _sessionStateChangedCb: function(H, G, I) {
            if (this.report_timer) {
                this.report_timer.cancel()
            }
            var J = G[0];
            if (J == "offline") {
                this.report_timer = null
            } else {
                this.report_timer = B.later(this.REPORT_INTERVAL, this, this.reportActivity, null, true)
            }
        },
        init: function() {
            var G = this;
            E = IMO.UI.X;
            E.call_when_manager_added("IMO.Manager.CommManager", function(H) {
                C = H.session
            });
            E.call_when_manager_added("IMO.Manager.SessionManager", function(H) {
                F = H;
                F.evSessionStateChanged.subscribe(G._sessionStateChangedCb, G, true)
            })
        }
    }
}());